package com.acme.bankapp.client;

import java.io.*;
import java.net.Socket;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Alfeya
 * Date: 06.12.14
 * Time: 20:15
 * To change this template use File | Settings | File Templates.
 */
public class BankClient {
    public static Socket socket;
    public static void main(String[] args) throws IOException {
        try {
            socket = new Socket("127.0.0.1", 9999);
            DataInputStream dis = new DataInputStream(socket.getInputStream());
            DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
            System.out.println("Session started. Please, enter command (request, exit):");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while(true) {
                String inputInfo;
                String line;
                do {
                    inputInfo = br.readLine();
                    dos.writeUTF(inputInfo);

                    line = dis.readUTF();
                    System.out.println(line);
                }
            while (!line.equals("exit"));
                System.out.println("Session ended. Closing connection.");
                socket.close();
                break;
            }
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }
}
